frappe.ui.form.on('Stock Entry Detail', {
    qty(frm, cdt, cdn) {
		let child = locals[cdt][cdn];
		if (
			child.s_warehouse && child.batch_no &&
			child.old_qty && (child.qty - child.old_qty) === 1
		){
		   child.qty = child.qty - 1;      // 不触发字段事件，避免递归
		   frm.refresh_field("items");
		   frm.set_df_property("scan_barcode","description", __("重复扫码"));
		}
		//child.old_qty = child.qty;
    },
	batch_no(frm, cdt, cdn) {
		let child = locals[cdt][cdn];
		frappe.call({
			method: "erpnext.stock.doctype.batch.batch.get_batch_qty",
			args: {
				batch_no: child.batch_no,
				warehouse: child.s_warehouse
			},
			callback: (r) => {
				if (r.message) {
				    child.qty = r.message;     // 不触发字段事件
				    child.old_qty = child.qty; // 保存正常扫码后的旧数量
				    refresh_field("items");
					//frappe.model.set_value(cdt, cdn, "qty", r.message);
				}
			}
		})
	}
})